package com.yjhb.android.sbz.fragment.mytask;

import android.view.View;

import com.yjhb.android.sbz.dialog.TipsDialog;
import com.yjhb.android.sbz.entity.MyTask;
import com.yjhb.android.sbz.enums.TaskStatus;
import com.yjhb.android.sbz.tool.Tool;

/**
 * 创建者 zx
 * 创建时间 2020/12/17 11:29
 */
public class DoingFragment extends MyTaskListFragment {
    private final String TAG = "HandingFragment";

    @Override
    protected void onLoadData(int size, int current) {
        presenter.getOrderList(TaskStatus.TASK_STATUS_TAKE.getStatus(), size, current);
    }

    @Override
    public CharSequence getTitle() {
        return "进行中";
    }


    @Override
    public void onViewClick(View view, String msg, int index, Object o) {
        MyTask myTask = (MyTask) o;
        if (msg.equals("btn1")) {
            //如果状态为超时就进入详情页重新编辑，不然这个按钮的做用是取消报名
            if (TaskStatus.getStatus(myTask.getState()) == TaskStatus.TASK_STATUS_TIMEOUT) {
                Tool.startEditTaskDetailActivity(getContext(), myTask.getTaskId());
            } else {
                TipsDialog tipsDialog = new TipsDialog(getContext());
                tipsDialog.setContent("确定取消报名？");
                tipsDialog.setTitle("提示");
                tipsDialog.setOnClickListener(new TipsDialog.OnClickListener() {
                    @Override
                    public void onClick(int type) {
                        if (type == TipsDialog.TYPE_SUBMIT) {
                            presenter.cancelTask(myTask.getId());
                        }
                        tipsDialog.dismiss();
                    }
                });
                tipsDialog.show();

            }
        } else if (msg.equals("btn2")) {
            if (TaskStatus.TASK_STATUS_TIMEOUT == TaskStatus.getStatus(myTask.getState()) ) {
                TipsDialog tipsDialog = new TipsDialog(getContext());
                tipsDialog.setContent("确定删除记录？");
                tipsDialog.setTitle("提示");
                tipsDialog.setOnClickListener(new TipsDialog.OnClickListener() {
                    @Override
                    public void onClick(int type) {
                        if (type == TipsDialog.TYPE_SUBMIT) {
                            presenter.deleteOrder(myTask.getId());
                        }
                        tipsDialog.dismiss();
                    }
                });
                tipsDialog.show();
            }
            if (TaskStatus.TASK_STATUS_TAKE == TaskStatus.getStatus(myTask.getState())){
                Tool.startEditTaskDetailActivity(getActivity(),myTask.getTaskId());
            }
        }
    }

    @Override
    public void onSuccess(String msg) {
        super.onSuccess(msg);
        if (msg != null && msg.equals("报名已取消")) {
            onLoadData(size, current);
        }
        if (msg != null && msg.equals("删除成功！")) {
            onLoadData(size, current);
        }
    }
}
